﻿using System;
using System.Collections.Generic;
using log4net;
using Needle.Bus.Messages;
using Needle.Bus.Tests.Engine.Queues;

namespace Needle.Bus.Tests.Engine
{
    public class TestHandler : IMessageHandler
    {
        private static ILog log = LogManager.GetLogger(typeof(TestHandler));

        public void Initialize()
        {
        
        }

        public void Process(IMessage message)
        {
            if (message is TestMessage)
            {
                var testMsg = (TestMessage)message;
                testMsg.Handled = true;
                log.DebugFormat("Handled message {0}.", testMsg.Number);
            }
            else
            {
                Bus.Send(BusAddress.RejectedMessages, message);
            }
        }

        public void Process(IList<IMessage> messages)
        {
            log.DebugFormat("Handling {0} messages", messages.Count);
            foreach (var msg in messages)
                Process(msg);
        }

        public void Dispose()
        {
             
        }

    }

    public class MessageDumper : IMessageHandler
    {

        public void Initialize()
        {

        }

        public void Process(IMessage message)
        {
        }

        public void Process(IList<IMessage> messages)
        {
        }

        public void Dispose()
        {

        }

    }
}
